<?php
namespace app\admin\controller\common;

use think\Request;
use app\admin\controller\Base;
use app\admin\service\common\UploadService;
use app\admin\model\common\UploadModel;
use app\admin\model\common\UploadCateModel;
use think\facade\Db;

class Upload extends Base
{
    //资源类型
    public function cate(Request $request){
        $model = new UploadCateModel();
        $data = $model->select()->toArray();
        return success($data);
    }
    //添加资源类型
    public function add(Request $request){
        $param = $this->request->param();
        $service = new UploadService();
        $data = $service->Add($param);
        return $data;
    }
    //编辑资源类型
    public function edit(Request $request){
        $param = $this->request->param();
        $service = new UploadService();
        $data = $service->Edit($param['id'], $param);
        return $data;
    }
    //删除资源类型
    public function del(Request $request){
        $data = $request->param();
        $ids = is_array($data['ids']) ? $data['ids'] : explode(',', $data['ids']);
        $service = new UploadService();
        return $service->delCate($ids);
    }
    //资源列表
    public function list(Request $request){
        $param = $request->param();
        $Service = new UploadService();
        $data = $Service->getList($param);
        return $data;
    }
    //移动资源
    public function move(Request $request){
        $param = $this->request->param();
        $service = new UploadService();
        $data = $service->Move($param['id'], $param);
        return $data;
    }
    //删除资源
    public function delete(Request $request){
        $data = $request->param();
        $ids = is_array($data['ids']) ? $data['ids'] : explode(',', $data['ids']);
        $service = new UploadService();
        return $service->Delete($ids);
    }
    //上传资源
    public function Upload()
    {
  
        $model = new UploadModel();
        $result = $model->upload(
            $class_id = 1, 
            $folder_name = 'files',
            $app = 2,
            $user_id = 0,
            $file = 'file', 
            $exts = []
        );
        return $result;
    }
}